<!-- 修改手机号 -->
<template>
  <el-dialog title="修改手机号" v-model="dialog" width="30%" @closed="closedFormDialog">
    <el-form :model="form" label-width="150px" v-loading="loading">
      <el-row :gutter="10">
        <el-col :span="20">
          <el-form-item label="手机号：" prop="mobile">
            <el-input v-model="form.mobile" placeholder="修改登录手机号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="1">
          <el-tooltip placement="top" content="如果修改了手机号，原先手机号中的订单就到新手机号下。如果新手机号本身就有订单，会被删除">
            <i class="el-icon-info"></i>
          </el-tooltip>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button :disabled="disabledbtn" @click="closedFormDialog">取 消</el-button>
        <el-button type="primary" :disabled="disabledbtn" @click="handlePutChangePhoneInfo">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import type { IChangeUserPhone } from "@/types/user";
import { putChangePhoneInfo } from "@/utils/api/user";
import { useState } from "@/hooks/useState.ts";
const { disabledbtn, loading, toggleState } = useState();
const dialog = defineModel<boolean>("dialog", { required: true });
const form = defineModel<IChangeUserPhone>("form", { required: true });
const emit = defineEmits<{
  handleSuccess: [];
}>();
/* 修改手机号 */
function handlePutChangePhoneInfo() {
  if (form.value.mobile === "") {
    ElMessage.warning("请填写手机号");
    return;
  }
  toggleState(true);
  putChangePhoneInfo(form.value)
    .then(() => {
      ElMessage.success("修改成功");
      emit("handleSuccess");
      closedFormDialog();
    })
    .catch(() => {})
    .finally(() => {
      toggleState(false);
    });
}

// 关闭模态框
function closedFormDialog() {
  dialog.value = false;
  form.value.mobile = "";
  form.value.id = 0;
}
</script>

<style lang="scss" scoped>
/* Add your styles here */
</style>
